package com.eduhzy.ttw.teacher.mvp.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.ObjectUtils;
import com.blankj.utilcode.util.SPUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.eduhzy.ttw.commonsdk.core.Constants;
import com.eduhzy.ttw.commonsdk.core.RouterHub;
import com.eduhzy.ttw.commonsdk.entity.MineInfo;
import com.eduhzy.ttw.commonres.utils.RxUtil;
import com.eduhzy.ttw.teacher.R;
import com.eduhzy.ttw.teacher.di.component.DaggerContactDetailsComponent;
import com.eduhzy.ttw.teacher.mvp.contract.ContactDetailsContract;
import com.eduhzy.ttw.teacher.mvp.presenter.ContactDetailsPresenter;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;

import butterknife.BindView;
import butterknife.OnClick;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * @author xubo
 * @date 2018-7-25 9:59:04
 */
@Route(path = RouterHub.APP_CONTACTDETAILSACTIVITY)
public class ContactDetailsActivity extends BaseActivity<ContactDetailsPresenter> implements ContactDetailsContract.View {
    @Autowired(name = Constants.ROUTER_STRING)
    String baseno;
    @BindView(R.id.iv_avatar)
    ImageView ivAvatar;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_no)
    TextView tvNo;
    private QMUITipDialog tipDialog;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        //如找不到该类,请编译一下项目
        DaggerContactDetailsComponent
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
        return R.layout.activity_contact_details;
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        mPresenter.getTargetByQrCode(baseno, SPUtils.getInstance().getString(Constants.USERID));
    }

    @Override
    public void showLoading() {
        if (tipDialog == null) {
            tipDialog = RxUtil.showLoading(this, "正在查找好友····");
        }
        tipDialog.show();
    }

    @Override
    public void hideLoading() {
        if (ObjectUtils.isNotEmpty(tipDialog)) {
            tipDialog.dismiss();
        }
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        RxUtil.showTipDialog(getActivity(), QMUITipDialog.Builder.ICON_TYPE_NOTHING, message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public Activity getActivity() {
        return this;
    }

    @Override
    public void update(MineInfo data) {
        tvName.setText(data.getRealName());
        tvNo.setText(data.getBaseNo());
        Glide.with(this)
                .load(data.getTempAvatar())
                .apply(RequestOptions.placeholderOf(R.drawable.img_touxiang).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL))
                .into(ivAvatar);
    }

    @OnClick(R.id.btn_submit)
    public void onViewClicked() {
    }
}
